home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Video Digitizer / MyGrabOneFrame ƒ / MyApplication.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  6.9 KB  |  308 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MyApplication.c
  3.     
  4.     Contains:    My Application Shell.
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        03/14/94    JW        Re-Created for Universal Headers.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    <Types.h>
  23. #include    <Memory.h>
  24. #include    <QuickDraw.h>
  25. #include    <Palettes.h>
  26. #include    <QDOffscreen.h>
  27. #include    <Errors.h>
  28. #include    <Fonts.h>
  29. #include    <Dialogs.h>
  30. #include    <Windows.h>
  31. #include    <Menus.h>
  32. #include    <Events.h>
  33. #include    <Desk.h>
  34. #include    <DiskInit.h>
  35. #include    <OSUtils.h>
  36. #include    <Resources.h>
  37. #include    <ToolUtils.h>
  38. #include    <AppleEvents.h>
  39. #include    <EPPC.h>
  40. #include    <GestaltEqu.h>
  41. #include    <Processes.h>
  42. #include    <Balloons.h>
  43. #include    <Aliases.h>
  44. #include    <MixedMode.h>
  45. #include    <Scrap.h>
  46. #include    <LowMem.h>
  47.  
  48. #include    <Movies.h>
  49. #include    <QuickTimeComponents.h>
  50.  
  51. #include    "MyApplication Shell (2.0).h"
  52. #include    "MyApplication.h"
  53.  
  54. /* ------------------------------------------------------------------------- */
  55.  
  56. //    These globals are used by the shell and must be defined:
  57.  
  58. Str255        gMyAboutTitle = "\pSample Application";
  59. Str255        gMyAboutDesc = "\pThis is a sample application shell.";
  60.  
  61. //    Add your own globals here:
  62.  
  63. struct WindowInfo {
  64.     long            stuff;
  65. };
  66. typedef        struct WindowInfo WindowInfo, *WindowInfoPtr, **WindowInfoHandle;
  67.  
  68. /* ------------------------------------------------------------------------- */
  69.  
  70. //    MyInitialize is called at init time after the toolbox is initialized.  This routine is
  71. //    called only once.
  72.  
  73. OSErr MyInitialize()
  74. {
  75.     OSErr        err;
  76.     long        QDfeature;
  77.     
  78.     //    We require QuickTime so make sure it is available.
  79.     if (err = Gestalt(gestaltQuickTime, &QDfeature))
  80.         return(err);
  81.         
  82.     if (err = EnterMovies())
  83.         return(err);
  84.     else
  85.         return(noErr);
  86. }
  87.  
  88. //    Depending on the value of the constant MYEVENTDEF, this routine may have different
  89. //    calling frequency.
  90. //    If MYEVENTDEF == 2, then this routine gets called for every
  91. //       window owned by the application of type MAS_WINDOWDOC per iteration of the event loop
  92. //       if the event is NOT a null event.  MyEvent can assume that the grafport and gdevice
  93. //       are set to the window being passed.
  94. //    If MYEVENTDEF == 1, then this routine gets called once per event loop is the
  95. //       event is NOT a null event.  theWindow will be nil.
  96. //    If MYEVENTDEF == 0, this routine never gets called.
  97. //    Returning true indicates that the event was handled and can be ignored by the normal
  98. //    event handler.
  99.  
  100. Boolean MyEvent(WindowPtr theWindow, EventRecord *myEvent)
  101. {
  102.     return ( false );
  103. }
  104.  
  105. //    Depending on the value of the constant MYIDLEDEF, this routine may have different
  106. //    calling frequency.
  107. //    If MYIDLEDEF == 2, then this routine gets called for every
  108. //       window owned by the application of type MAS_WINDOWDOC per iteration of
  109. //       the event loop.  You can assume that the port and gdevice are set to the window.
  110. //    If MYIDLEDEF == 1, then this routine gets called once per event loop.  theWindow will be nil.
  111. //    If MYIDLEDEF == 0, this routine never gets called.
  112.  
  113. void MyIdle(WindowPtr theWindow)
  114. {
  115. }
  116.  
  117. //    MyDraw is called when redrawing the window is needed.  The port and gdevice
  118. //    is already set and begin and end update are called for MyDraw.
  119.  
  120. void MyDraw(WindowPtr theWindow)
  121. {
  122. }
  123.  
  124. //    This routine gets called once when the application is quitting.
  125. //    This gives the app the chance to clean up.
  126.  
  127. void MyFinishup()
  128. {
  129. }
  130.  
  131. //    This routine is called whenever the app receives a suspend or resume event.  This
  132. //    allows the yield time (passed to WaitNextEvent) to be changed.  I.e., if you don't
  133. //    do much processing the in background, you should set the yield to a high value
  134. //    when the suspend message is received.
  135.  
  136. long MyYieldTime(long message)
  137. {
  138.     if ( message )
  139.         //    Resume message
  140.         return ( 0 );
  141.     else
  142.         //    Suspend message
  143.         return ( 30 );
  144. }
  145.  
  146. //    If the shell's doCommand routine can not process the menu selection, then this routine is
  147. //    called.  Do not call HiliteMenu because it is called by the shell.
  148. //    If the command can not be handled, this it must be an error and the shell will
  149. //    present a FATAL error to the user.
  150.  
  151. OSErr MyDoCommand(short theMenu, short theItem)
  152. {
  153.     switch ( theMenu ) {
  154.         case kMENU_NEXTID:
  155.             switch ( theItem ) {
  156.                 case kMENU_NEXT1stITEM:
  157.                     break;
  158.                 default:
  159.                     return ( theItem );
  160.             }
  161.             break;
  162.             
  163.         default:
  164.             return ( theItem );
  165.     }
  166.     
  167.     return ( noErr );
  168. }
  169.  
  170. void MyDoKeyDown(EventRecord *myEvent)
  171. {
  172. }
  173.  
  174. void MyInContent(WindowPtr foundWindow, Point where)
  175. {
  176. }
  177.  
  178. void MyZoomWindow(WindowPtr foundWindow, short windowPart)
  179. {
  180.     if ( windowPart == 8 ) {
  181.     } else {
  182.     }
  183.  
  184.     ZoomWindow(foundWindow, windowPart, true);
  185. }
  186.  
  187. void MyAdjustMenus()
  188. {
  189. }
  190.  
  191. /* ------------------------------------------------------------------------- */
  192.  
  193. void MyNew()
  194. {
  195.     WindowPtr                myWindow;
  196.     Rect                    myBounds = {42, 4, 522, 644};
  197.     WindowInfoHandle        myWinfo;
  198.     Component                vThing;
  199.     ComponentDescription    vThingDesc;
  200.     ComponentInstance        vThingInst;
  201.     Rect                    maxSrcRect, activeRect, globalRect;
  202.     PixMapHandle            videoPixMapH;
  203.     
  204.     myWindow = NewCWindow(0L, &myBounds, "\pWindow!", 1, documentProc, (WindowPtr) -1, true, 0L);
  205.     SetMyWindow(myWindow);
  206.     SetPort(myWindow);
  207.     SetGDevice(GetMainDevice());
  208.     myWinfo = (WindowInfoHandle) NewHandle(sizeof(WindowInfo));
  209.     SetWRefCon(myWindow, (long) myWinfo);
  210.     (**myWinfo).stuff = 0;
  211.     
  212.     vThingDesc.componentType = 'vdig';
  213.     vThingDesc.componentSubType = 0;
  214.     vThingDesc.componentManufacturer = 0;
  215.     vThingDesc.componentFlags = 0;
  216.     vThingDesc.componentFlagsMask = 0;
  217.     vThing = FindNextComponent((Component) 0, &vThingDesc);
  218.     vThingInst = OpenComponent(vThing);
  219.     
  220.     VDGetMaxSrcRect(vThingInst, ntscIn, &maxSrcRect);
  221.     VDGetActiveSrcRect(vThingInst, ntscIn, &activeRect);
  222.     VDSetDigitizerRect(vThingInst, &activeRect);
  223.     
  224.     globalRect = myWindow->portRect;
  225.     videoPixMapH = (PixMapHandle) NewHandle(sizeof(PixMap));
  226.     **videoPixMapH = **((* (CGrafPort *) myWindow).portPixMap);
  227.     VDSetPlayThruOnOff(vThingInst, vdPlayThruOff);
  228.     VDSetPlayThruDestination(vThingInst, videoPixMapH, &globalRect, nil, nil);
  229.     VDSetPlayThruOnOff(vThingInst, vdPlayThruOn);
  230.     do {
  231.     } while ( !Button() );
  232.     VDGrabOneFrame(vThingInst);
  233. }
  234.  
  235. //    If theFSS is not nil, then the file to be opened is specified in the FSSpec.
  236. //    MyOpen must make window frontmost so that it can be printed from finder.
  237. void MyOpen(FSSpec *theFSS)
  238. {
  239.     SysBeep(50);
  240. }
  241.  
  242. void MyClose()
  243. {
  244.     WindowPtr            closeWindow;
  245.     WindowInfoHandle    myWinfo;
  246.     
  247.     closeWindow = FrontWindow();
  248.     if ( closeWindow == nil )
  249.         return;
  250.         
  251.     myWinfo = (WindowInfoHandle) GetWRefCon(closeWindow);
  252.  
  253.     DisposHandle((Handle) myWinfo);
  254.     DisposeWindow(closeWindow);
  255. }
  256.  
  257. void MySave()
  258. {
  259.     SysBeep(50);
  260. }
  261.  
  262. void MySaveAs()
  263. {
  264.     SysBeep(50);
  265. }
  266.  
  267. void MyPageSetup()
  268. {
  269.     SysBeep(50);
  270. }
  271.  
  272. void MyPrint()
  273. {
  274.     SysBeep(50);
  275. }
  276.  
  277. /* ------------------------------------------------------------------------- */
  278.  
  279. void MyUndo(void)
  280. {
  281.     SysBeep(50);
  282. }
  283.  
  284. void MyCut(void)
  285. {
  286.     SysBeep(50);
  287. }
  288.  
  289. void MyCopy(void)
  290. {
  291.     SysBeep(50);
  292. }
  293.  
  294. void MyPaste(void)
  295. {
  296.     SysBeep(50);
  297. }
  298.  
  299. void MyClear(void)
  300. {
  301.     SysBeep(50);
  302. }
  303.  
  304. void MySelectAll(void)
  305. {
  306.     SysBeep(50);
  307. }
  308.